package cc.wsyw126.java.jvm;

import java.util.concurrent.TimeUnit;

/**
 * Created by junpeng.yang on 17/3/19.
 */
public class Adaemon implements Runnable {

    @Override
    public void run() {
        try {
            System.out.println("Starting ADaemon");
            TimeUnit.MILLISECONDS.sleep(4);
        } catch (InterruptedException e) {
            System.out.print("Exiting via InterruptedException");
        } finally {
            System.out.println("the finally really run?");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Adaemon ad = new Adaemon();
        Thread thread = new Thread(ad);
        thread.setDaemon(true); //如果注释掉这行，finally语句块将会执行
        thread.start();
        TimeUnit.MILLISECONDS.sleep(1);
    }
}